<?php

namespace app\admin\model;

use think\Model;

class Category extends BaseModel
{
    static protected $modelObj = "app\admin\model\Category";

    static public function addCategory($data)
    {
        if ($data['pid'] != 0) {
            $parentData = Category::where("id", $data['pid'])->find();
            $data['tree'] = $parentData['tree'] . "," . $data['pid'];
        }
        return Category::create($data);
    }


    static public function edit($id, $data)
    {
        if ($data['pid'] != 0) {
            $parentData = Category::where("id", $data['pid'])->find();
            $data['tree'] = $parentData['tree'] . "," . $data['pid'];
        }
        return Category::update($data, ['id'=>$id]);
    }

}